﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;


namespace project9
{
    public partial class Form1 : Form
    {
        private string connectionString = "YourConnectionString"; // 替换为你的数据库连接字符串
        private SqlConnection connection;
        private SqlCommand command;
        private SqlDataReader reader;

        private string currentWord;
        public Form1()
        {
            InitializeComponent();
            connection = new SqlConnection(connectionString);
            command = new SqlCommand();
            command.Connection = connection;
        }

        private void englishWordLabel_Click(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {
            string answer = answerTextBox.Text;
            CheckAnswer(answer);
            answerTextBox.Clear();
            LoadRandomWord();
        }

        private void button1_Click(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            connection.Open();
            LoadRandomWord();
        }
        private void LoadRandomWord()
        {
            command.CommandText = "SELECT TOP 1 EnglishWord FROM Words ORDER BY NEWID()";
            reader = command.ExecuteReader();
            if (reader.Read())
            {
                currentWord = reader["EnglishWord"].ToString();
                englishWordLabel.Text = currentWord;
            }
            reader.Close();
        }
        private void CheckAnswer(string answer)
        {
            if (answer.ToLower() == currentWord.ToLower())
            {
                resultLabel.Text = "正确";
            }
            else
            {
                resultLabel.Text = "错误";
            }
        }
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            connection.Close();
        }
    }
}
